package tecpointbenchmark.model;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

import tecpointbenchmark.model.dto.ResultDTO;

/**
 * Reporthandler 
 * 
 * @author Linus
 */
public class ReportHandler {

	/*
	 * Writes a report for modules results . Including date and time the test
	 * was executed and how it was exited, and an additional message-string.
	 * Writing it to the file logg.txt.
	 * 
	 * @param result , Result of a module
	 */
	public void writeReport(ResultDTO result) {
		String timeWritten;
		String finishStatus;
		Date calendarTime = new Date();
		calendarTime.setTime(result.getTime());
		// format date
		timeWritten = calendarTime.toString() + "\t";
		// format exit status
		if (result.getNumber() == 0)
			finishStatus = "Test finished without problems\t ";
		else if (result.getNumber() == 1)
			finishStatus = "Test was manually aborted\t ";
		else if (result.getNumber() == 2)
			finishStatus = "Test exited with an error\t ";
		else
			finishStatus = "Test exited with unknown error "
					+ result.getNumber() + "\t ";

		try {
			FileWriter out = new FileWriter("logg.txt", true);

			out.append(timeWritten);
			out.append(finishStatus);
			out.append(result.getMessage() + "\n");
			out.close();
		} catch (IOException e) {
		}

	}

}
